package com.storm.lib.util;

import net.sf.ehcache.config.TerracottaConfiguration.Consistency;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.storm.lib.type.Constant;

/**
 *
 * 类功能: 用于获得Spring相关Bean的类
 * @author johnny
 * @version 2010-11-26
 */
public class BeanUtil{
//	protected final static Logger logger = Logger.getLogger(BeanUtil.class);
	public static ApplicationContext applicationContext=null;

	/**
	 *
	 * 方法功能:设置
	 * 更新时间:2010-10-27, 作者:johnny
	 */
	public static synchronized void setDefaultApplicationContext(){
		if(applicationContext==null){
			String path = FileUtil.getFileBinPath() + Constant.SPRING_CONFIG_MAIN_RELATED_PATH;
			ApplicationContext context = new FileSystemXmlApplicationContext(path);
			applicationContext = context;
		}
	}

	public static Object getBean(String beanName) {
		Object ob = BeanUtil.getApplicationContext().getBean(beanName);
		return ob;
	}

	public static Object getBean(Class clazz) {
		Object ob = BeanUtil.getApplicationContext().getBean(clazz);
		return ob;
	}

	public static  ApplicationContext getApplicationContext() {
		if(applicationContext==null){
			setDefaultApplicationContext();
		}
		return applicationContext;
	}


}
